#!/usr/bin/python3
# -*- coding: utf-8 -*-

import re

import allure
from playwright.sync_api import Page

from models.base_page import BasePage


class IntranetRouterPage(BasePage):
    def __init__(self, page: Page):
        super().__init__(page)
        self.route = "intranet_routers"

    def check_intranet_router_page_user_guide_element_to_be_visible(self):
        """检查使用指南元素是否可见"""
        with allure.step("检查IntranetRouterPage:使用指南元素是否可见"):
            self.expect.to_be_visible(self.page.locator(".intro"))  # 使用指南栏目
            self.expect.to_be_visible(self.page.locator("li").filter(has_text="边界路由器").get_by_role("link"))
            self.expect.to_be_visible(self.page.get_by_text("使用指南"))
            self.expect.to_be_visible(self.page.get_by_text("收起"))
            self.expect.to_be_visible(self.page.locator(".svg-icon > use"))
            self.expect.to_contain_text(self.page.locator(".tab-intro .text"),
                                        "边界路由器是用于连接不同网络的路由器，边界路由器可以连接多种不同的网络场景")

    def check_intranet_router_page_table_element_to_be_visible(self):
        """检查工具栏及table是否可见"""
        with allure.step("检查IntranetRouterPage:工具栏及table是否可见"):
            self.expect.to_be_visible(self.page.locator(".table-toolbar"))
            self.expect.to_be_visible(self.page.get_by_role("link", name="G", exact=True))
            self.expect.to_be_visible(self.page.locator("a").filter(has_text=re.compile(r"^创建$")))
            self.expect.to_be_visible(self.page.get_by_placeholder(" "))
            self.expect.to_be_visible(self.page.get_by_role("combobox"))
